package com.huangyi;

public class Main {
    public static void main(String[] args) {
        //消失的两个数字
        class Solution {
            public int[] singleNumber(int[] nums) {
                // 第一次整体异或，得到 a ^ b
                int tmp = 0;
                for (int num : nums) {
                    tmp ^= num;
                }

                // 找到最低位不同的标志位
                int mark = Integer.lowestOneBit(tmp);

                // 分组异或
                int a = 0, b = 0;
                for (int num : nums) {
                    if ((num & mark) == 0) {
                        a ^= num;
                    } else {
                        b ^= num;
                    }
                }

                return new int[]{a, b};
            }
        }

        //替换所有的问号
        class Solution2 {
            public String modifyString(String s) {
                char[] ch = s.toCharArray();
                for (int i = 0; i < ch.length; i++) {
                    if (ch[i] == '?') {
                        for (char c = 'a'; c <= 'z'; c++) {
                            boolean leftOk = (i == 0 || ch[i - 1] != c);
                            boolean rightOk = (i == ch.length - 1 || ch[i + 1] != c);
                            if (leftOk && rightOk) {
                                ch[i] = c;
                                break;
                            }
                        }
                    }
                }
                return new String(ch);
            }
        }
    }
}